﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace Läxomatic
{
    class Task
    {
        int _submitStatus;
        int _gradeStatus;
        private bool _mandatory;
        private bool _active;
        private string _submitId;
        private int _maxpoints;

        public Task(int grade, int submit, bool mandatory, string submitId, int maxpoints)
        {
            //Aktivt(ifyllt) task
            _active = true;
            _mandatory = mandatory;
            _gradeStatus = grade;
            _submitStatus = submit;
            _submitId = submitId;
            _maxpoints = maxpoints;
        }
        public Task()
        {
            //Svart(tomt)task.
            _active = false;
        }
        //Returnerar en knapp med rätt färg
        public Button Draw(Point p, Size s)
        {
            Button temp = new Button();
            temp.Location = p;
            temp.Size = s;

            if (_active)
            {
                temp.Click += new EventHandler(temp_Click);
                if (_submitStatus == 0 || _gradeStatus == 2)
                    if (!_mandatory)
                        temp.BackColor = Color.Gray;
                    else
                        temp.BackColor = Color.DarkRed;
                if (_gradeStatus == 0 && _submitStatus != 0)
                    temp.BackColor = Color.Yellow;
                if (_gradeStatus == 1)
                    if (_maxpoints > 0 && _submitStatus == 1)
                        temp.BackColor = Color.Green;
                    else
                        temp.BackColor = Color.Blue;
            }
            else
                temp.BackColor = Color.Black;


            return temp;
        }
        //returnerar id
        public string getId()
        { return this._submitId; }
        //Öppnar en uppgiftInstans, dvs hanteringsfödneter för en specifik uppgift.
        private void temp_Click(Object sender, System.EventArgs e)
        {
            SavedData.currentTask = this;
            SavedData.mainPanel.Controls.Clear();
            UppgiftInstans tempUppg = new UppgiftInstans();
            foreach (Control x in tempUppg.Controls)
            {
                SavedData.mainPanel.Controls.Add(x);
                if (x.Name == "panel9")
                    foreach (Control y in x.Controls)
                    {
                        if (y.Name == "btn_comment")
                        SavedData.mainform.AcceptButton = (Button)y;
                        if (y.Name == "btn_back")
                            SavedData.mainform.CancelButton = (Button)y;
                        
                    }

            }

        }

    }
}
